﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpdateHead : MonoBehaviour
{
	public GameObject Neck;
	public float HeadNeckZ;
	public Transform Head;
	Vector3 HeadNeckOffset;
	// Start is called before the first frame update
	void Start()
	{
		//方向向量
		HeadNeckOffset = (Head.position - Neck.transform.position).normalized;
		HeadNeckZ = 90f;
	}

	// Update is called once per frame
	void Update()
	{
		float RotateAngle = Vector3.Angle(HeadNeckOffset, (Head.position - Neck.transform.position).normalized);
		if (Vector3.Cross(HeadNeckOffset, (Head.position - Neck.transform.position).normalized).z > 0)
		{
			RotateAngle = -RotateAngle;
		}
		Quaternion angle = new Quaternion();
		angle.eulerAngles = new Vector3(0, 0, HeadNeckZ - RotateAngle);
		Neck.transform.rotation = angle;
	}
}
